package com.xyhuo.leetcode.december;

/**
 * x的平方根
 * https://leetcode.cn/problems/sqrtx/
 *
 * @time 2023/12/26
 */
public class MySqrt {

//    public static void main(String[] args) {
//        MySqrt ms = new MySqrt();
//        ms.mySqrt(4);
//    }

    public int mySqrt(int x) {
        int index = 0;
        while (true) {
            if (index * index < 0) {
                return index - 1;
            }
            if (index * index < x) {
                index++;
            } else if (index * index == x) {
                return index;
            } else {
                return index - 1;
            }
        }
    }
}
